// TestServer.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "Client.h"
#include "DBService.h"
#include "msgDBServer.h"

void CDBService::StartServer( xgc_lpcstr address, xgc_uint16 port, xgc_uint16 test_invent, xgc_uint16 timeout )
{
	net::IMessageQueue* mQueue = GetMessageQueue();
	mServer = net::StartServer( address, port, &mQueue, test_invent, timeout, net::ProtocalDefault, 10 );

	__super::Start();
}

void CDBService::StopServer()
{
	net::CloseServer( mServer );
	__super::Stop();
}

void CDBService::RegisteMessage()
{
	RegistFunction( C2LS_LOGIN_MESSAGE_TYPE, C2LS_LOGIN_REQUEST, &ProcessLogin );
}

xgc_lpvoid CDBService::CreateUserdata( net::network_t h )
{
	return reinterpret_cast< xgc_lpvoid >( new CClient );
}

void CDBService::DestroyUserdata( xgc_lpvoid userdata )
{
	delete reinterpret_cast< CClient* >( userdata );
}

//////////////////////////////////////////////////////////////////////////
int ProcessLogin( net::network_t h, xgc_lpvoid u, const unsigned char* data, size_t size )
{
	msgDBResponse rpn;
	rpn.username = "";
	rpn.check = TRUE;

	SendMessage( h, rpn, 1024 );
	return 0;
}